home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / mach / hurd / sigsuspend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-23  |  2.6 KB  |  80 lines

  1. /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <hurd.h>
  22. #include <hurd/signal.h>
  23. #include <hurd/msg.h>
  24.  
  25. /* Change the set of blocked signals to SET,
  26.    wait until a signal arrives, and restore the set of blocked signals.  */
  27. int
  28. DEFUN(sigsuspend, (set), CONST sigset_t *set)
  29. {
  30.   struct hurd_sigstate *ss;
  31.   sigset_t newmask, oldmask, pending;
  32.   mach_port_t wait;
  33.   mach_msg_header_t msg;
  34.  
  35.   if (set != NULL)
  36.     /* Crash before locking.  */
  37.     newmask = *set;
  38.  
  39.   /* Get a fresh port we will wait on.  */
  40.   wait = __mach_reply_port ();
  41.  
  42.   ss = _hurd_self_sigstate ();
  43.  
  44.   oldmask = ss->blocked;
  45.   if (set != NULL)
  46.     /* Change to the new blocked signal mask.  */
  47.     ss->blocked = newmask & ~_SIG_CANT_MASK;
  48.  
  49.   /* Notice if any pending signals just became unblocked.  */
  50.   pending = ss->pending & ~ss->blocked;
  51.  
  52.   /* Tell the signal thread to message us when a signal arrives.  */
  53.   ss->suspended = wait;
  54.   __mutex_unlock (&ss->lock);
  55.  
  56.   if (pending)
  57.     /* Tell the signal thread to check for pending signals.  */
  58.     __sig_post (_hurd_msgport, 0, __mach_task_self ());
  59.  
  60.   /* Wait for the signal thread's message.  */
  61.   __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
  62.           MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
  63.   __mach_port_destroy (__mach_task_self (), wait);
  64.  
  65.   __mutex_lock (&ss->lock);
  66.   ss->blocked = oldmask;    /* Restore the old mask.  */
  67.   pending = ss->pending & ~ss->blocked;    /* Again check for pending signals.  */
  68.   __mutex_unlock (&ss->lock);
  69.  
  70.   if (pending)
  71.     /* Tell the signal thread to check for pending signals.  */
  72.     __sig_post (_hurd_msgport, 0, __mach_task_self ());
  73.     
  74.   /* We've been interrupted!  And a good thing, too.
  75.      Otherwise we'd never return.
  76.      That's right; this function always returns an error.  */
  77.   errno = EINTR;
  78.   return -1;
  79. }
  80.